package test;

import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Writer;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Scanner;

import org.apache.mina.transport.socket.SocketAcceptor;

public class Conntest {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		
		
		try {
			final Socket s = new Socket("192.168.0.200", 9300);
			
			
			PrintWriter writer = new PrintWriter(s.getOutputStream());
			
			
			
			Thread t = new Thread(new Runnable() {
				public void run() {
					
					
					Scanner sc;
					try {
						sc = new Scanner(s.getInputStream());
					
					
					while(sc.hasNext()) {
					
						String in = sc.next();
						
						
						if(in.equals("FMSTlg")) {
							
							sc.next();
							sc.next();
							sc.next();
							sc.next();
							String schleife = sc.next();
							String status = sc.next();
							
							System.out.println("Schleife " + schleife + " " + status);
							
							sc.next();
							sc.next();
							sc.next();
							sc.next();
							sc.next();
							sc.next();
							sc.next();
							sc.next();
						
						}
						else {
							System.out.println(in);
						}
						
					}
					
					System.out.println("closed");
					
					sc.close();
					} catch (IOException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			});
			
			t.start();
			
			Thread.sleep(4000);
			
			writer.write("allfms");
			writer.flush();
			
			writer.write("FMSTlg 16");
			
			writer.flush();
//			Thread.sleep(400000);
//			
//			writer.close();
			
			
		} catch (UnknownHostException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		

	}

}
